Fix #32
authorjustbur <justin@burkett.cc>
Mon, 13 Jul 2015 00:04:34 +0000 (20:04 -0400)
committerjustbur <justin@burkett.cc>
Mon, 13 Jul 2015 00:04:34 +0000 (20:04 -0400)
Main problem was a replacement regexp that looked for a forward slash in
the description, which removed group:x/y

which-key.el

index 10c4b917bbce6450bd7067a72a58e95bf4a7032f..c31166677c66c16ec0b6a2659c3f783c57926f8e 100644 (file)
@@ -65,7 +65,7 @@ in the first example."
   :group 'which-key
   :type '(alist :key-type regexp :value-type string))
 (defcustom which-key-description-replacement-alist
-  '(("Prefix Command" . "prefix") (".+/\\(.+\\)" . "\\1")
+  '(("Prefix Command" . "prefix")
     ("select-window-\\([1-9]\\)" . "Window \\1"))
   "See `which-key-key-replacement-alist'.
 This is a list of lists for replacing descriptions.  The second
@@ -609,6 +609,20 @@ corresponding `which-key-special-key-face'."
                     (substring key-w-face end (length key-w-face))))
         key-w-face))))
 
+(defun which-key/propertize-description (description)
+  (let* ((desc description)
+         (group-prfx (string-match-p "^group:" desc))
+         (group (or group-prfx
+                    (keymapp (intern desc))
+                    (string-match-p "^Prefix" desc)))
+         (desc (if group-prfx (substring desc 6) desc))
+         (desc (if group (concat "+" desc) desc))
+         (desc (which-key/truncate-description desc)))
+    (propertize desc 'face
+                (if group
+                    'which-key-group-description-face
+                  'which-key-command-description-face))))
+
 (defsubst which-key/truncate-description (desc)
   "Truncate DESC description to `which-key-max-description-length'."
   (if (> (length desc) which-key-max-description-length)
@@ -631,16 +645,8 @@ alists. Returns a list (key separator description)."
               (desc (which-key/maybe-replace
                      desc which-key-description-replacement-alist))
               (desc (which-key/maybe-replace-key-based desc keys))
-              (group (string-match-p "^group:" desc))
-              (desc (if group (substring desc 6) desc))
-              (prefix (string-match-p "^Prefix" desc))
-              (desc (if (or prefix group) (concat "+" desc) desc))
-              (desc-face (if (or prefix group)
-                             'which-key-group-description-face
-                           'which-key-command-description-face))
-              (desc (which-key/truncate-description desc))
               (key-w-face (which-key/propertize-key key))
-              (desc-w-face (propertize desc 'face desc-face))
+              (desc-w-face (which-key/propertize-description desc))
               (key-width (length (substring-no-properties key-w-face))))
          (setq max-key-width (max key-width max-key-width))
          (list key-w-face sep-w-face desc-w-face)))